import { setService, request } from '@/common/request'
import router from '@/router/index'
import { setToken, setUserInfo } from '@/common/auth'

// 登录方法
export function login(username, password, isAutoLogin) {
  const data = {
    username,
    password,
    isAutoLogin
  }
  return request({
    url: '/customerLogin',
    headers: {
      // isToken: false
    },
    method: 'post',
    data: data
  }).then(res => {
    // 数据存储
    setToken(res.data.token)
    setUserInfo(res.data.user)
    router.push({ path: "/" }).catch(err => {
      console.log(err)
    })
  }).catch(err => {
    console.error(err)
  })
}
// 登录方法
export function loginT(username, password, isAutoLogin) {
  const data = {
    username,
    password,
    isAutoLogin
  }
  return request({
    url: '/customerLogin',
    headers: {
      // isToken: false
    },
    method: 'post',
    data: data
  }).then(res => {
    // 数据存储
    setToken(res.data.token)
    setUserInfo(res.data.user)
    router.push({ path: "/" }).catch(err => {
      console.log(err)
    })
  }).catch(err => {
    console.error(err)
  })
}